import Vue from 'vue'
import App from './App'
import uView from "uview-ui"
import miToast from '@/components/mi-toast.vue'
import store from '@/store'
import Json from './Json' //测试用数据
Vue.use(uView)

Vue.config.productionTip = false
App.mpType = 'app'

Vue.prototype.proxy = 'https://bird.ioliu.cn/v1?url='

let vuexStore = require("@/store/$u.mixin.js");
Vue.mixin(vuexStore);

Vue.component('mi-toast', miToast)

const msg = (title, icon = 'none', duration = 1500, mask = false) => {
	// 全局统一提示
	if (Boolean(title) === false) {
		return;
	}
	uni.showToast({
		title,
		duration,
		mask,
		icon
	});
}

const loading = (statu, title = '加载中') => {
	// Loading
	if (Boolean(statu) === false) {
		uni.hideLoading();
	} else {
		uni.showLoading({
			title
		});
	}
}

const json = type => {
	// 模拟异步请求数据
	return new Promise(resolve => {
		setTimeout(() => {
			resolve(Json[type]);
		}, 500)
	})
}

Vue.prototype.$api = {
	msg,
	json,
	loading
}


const app = new Vue({
	store,
	...App
})

// http拦截器，将此部分放在new Vue()和app.$mount()之间，才能App.vue中正常使用
import httpInterceptor from '@/common/http.interceptor.js'
Vue.use(httpInterceptor, app)

// http接口API集中管理引入部分
import httpApi from '@/common/http.api.js'
Vue.use(httpApi, app)

app.$mount()
